public class ThreadDemo1 {
        static class Counter{
            public int count=0;

            synchronized void create() {
                count++;
            }

            synchronized void create1(){
                create();
            }
            synchronized void create2(){
                create1();
            }
        }
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread t1 = new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 50000; i++) {
                    counter.create();
                }
            }
        };
        Thread t2 = new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 50000; i++) {
                    counter.create2();
                }
            }
        };
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println(counter.count);
    }
}
